//
//  CollectionLeftViewController.m
//  myDemo2
//
//  Created by wuxueying on 5/8/14.
//
//

#import "CollectionLeftViewController.h"
#import "UICollectionViewLeftAlignedLayout.h"

static NSString * const kCellIdentifier = @"CellIdentifier";
@interface CollectionLeftViewController ()<UICollectionViewDataSource, UICollectionViewDelegateLeftAlignedLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@implementation CollectionLeftViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor clearColor];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCellIdentifier];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 100;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
    
    cell.contentView.layer.borderColor = [UIColor blueColor].CGColor;
    cell.contentView.layer.borderWidth = 2;
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat randomWidth = (arc4random() % 120) + 60;
    return CGSizeMake(randomWidth, (arc4random() % 120 +20));
}

@end
